using Finance.Api.Write.Applications.Commands.库存调拨;
using Finance.Api.Write.Applications.Commands.调拨入库管理;
using Finance.Api.Write.Applications.Commands.调拨出库管理;
using Finance.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Finance.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeploymentController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<DeploymentController> logger;

        public DeploymentController(IMediator mediator, ILogger<DeploymentController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 库存调拨添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeployment(DeploymentAddCommand request)
        {
            try
            {
                logger.LogInformation("库存调拨信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存调拨删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteDeployment(DeploymentDeleteCommand request)
        {
            try
            {
                logger.LogInformation("库存调拨信息删除");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存调拨批量删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> BatchDeleteDeployment(DeploymentBatchDeleteCommand request)
        {
            try
            {
                logger.LogInformation("库存调拨信息批量删除");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 调拨入库添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeployGoin(DeployGoinAddCommand request)
        {
            try
            {
                logger.LogInformation("调拨入库信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 调拨出库添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddDeployOut(DeployOutAddCommand request)
        {
            try
            {
                logger.LogInformation("调拨出库信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }
    }
} 